import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import viteCompression from 'vite-plugin-compression'
import VueDevTools from 'vite-plugin-vue-devtools'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  build: { assetsDir: 'static', },
  plugins: [
    vue(),
    Components({
      // vant组件自动引入
      resolvers: [VantResolver()],
    }),
    // 方法自动引入
    AutoImport({
      imports: [
        'vue',
        {
          'vant': [
            'showFailToast',
            'showSuccessToast',
            'showLoadingToast',
            'closeToast',
            'showToast',
            'showImagePreview',
            'showConfirmDialog',
          ],
          '@/utils/request': [
            'request'
          ],
          '@/utils/index': [
            'parseTime'
          ]
        }
      ]
    }),
    // 代码gzip压缩
    viteCompression(),
    // 开发调试工具
    VueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
